package org.atovio.coolexam.mapper;

import org.apache.ibatis.annotations.*;
import org.atovio.coolexam.entity.ExamPaperQuestionCustomerAnswer;

import java.util.List;
import java.util.Map;

public interface ExamPaperQuestionCustomerAnswerMapper {

    @Insert("""
            insert into t_exam_paper_question_customer_answer (id, question_id, exam_paper_id, exam_paper_answer_id, customer_score,
            answer, is_correct, create_user_id, create_time, item_order)
            values (#{id},#{questionId},#{examPaperId},#{examPaperAnswerId},#{customerScore},
            #{answer},#{isCorrect},#{createUserId},#{createTime},#{itemOrder});
            """)
    int insert(ExamPaperQuestionCustomerAnswer examPaperQuestionCustomerAnswer);

    @Select("select * from t_exam_paper_question_customer_answer;")
    List<ExamPaperQuestionCustomerAnswer> selectAll();

    @Select("select * from t_exam_paper_question_customer_answer where id = #{id};")
    ExamPaperQuestionCustomerAnswer selectById(Integer id);

    @Select("select * from t_exam_paper_question_customer_answer where question_id = #{questionId};")
    List<ExamPaperQuestionCustomerAnswer> selectByQuestionId(Integer questionId);

    @Select("select * from t_exam_paper_question_customer_answer where exam_paper_id = #{examPaperId};")
    List<ExamPaperQuestionCustomerAnswer> selectByExamPaperId(Integer examPaperId);

    @Select("select * from t_exam_paper_question_customer_answer where exam_paper_answer_id = #{examPaperAnswerId};")
    List<ExamPaperQuestionCustomerAnswer> selectByExamPaperAnswerId(Integer examPaperAnswerId);

    @Select("select * from t_exam_paper_question_customer_answer where create_user_id = #{CreateUserId};")
    List<ExamPaperQuestionCustomerAnswer> selectByCreateUserId(Integer CreateUserId);

    /**
     * 根据自定义条件查询记录条数
     *
     * @param criteria 自定义条件
     * @return 记录条数
     */
    int selectCountSelective(@Param("criteria") Map<String, Object> criteria);

    List<ExamPaperQuestionCustomerAnswer> selectSelective(@Param("criteria") Map<String, Object> criteria);

    @Update("update t_exam_paper_question_customer_answer set customer_score = #{customerScore} where id = #{id};")
    int updateCustomerScoreById(Integer id, Integer customerScore);

    @Update("update t_exam_paper_question_customer_answer set answer = #{answer} where id = #{id};")
    int updateAnswerById(Integer id, String answer);

    @Update("update t_exam_paper_question_customer_answer set is_correct = #{isCorrect} where id = #{id};")
    int updateIsCorrectById(Integer id, Integer isCorrect);

    @Delete("delete from t_exam_paper_question_customer_answer where id = #{id};")
    int deleteById(Integer id);
}
